package com.onekbase.demo.spring.bean;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.*;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

public class LifeBean implements BeanNameAware, BeanFactoryAware,
        ApplicationContextAware, InitializingBean, DisposableBean {

    private String testName;

    public LifeBean(){
        System.out.println("LifeBean Initializing ");
    }

    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        System.out.println("LifeBean.setBeanFactory invoke");
    }

    public void setBeanName(String name) {
        System.out.println("LifeBean.setBeanName invoke");
    }

    public void destroy() throws Exception {
        System.out.println("LifeBean.destory invoke");
    }

    public void afterPropertiesSet() throws Exception {
        System.out.println("LifeBean.afterPropertiesSet invoke");
    }

    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        System.out.println("LifeBean.setApplicationContext invoke");
    }

    public String getTestName() {
        return testName;
    }

    public void setTestName(String testName) {
        this.testName = testName;
        System.out.println("setTestName: " + testName);
    }

    public void myPostConstruct(){
        System.out.println("LifeBean.myPostConstruct invoke");
    }

    // 自定义初始化方法
    @PostConstruct
    public void springPostConstruct(){
        System.out.println("LifeBean @PostConstruct");
    }

    public void myPreDestory(){
        System.out.println("LifeBean.myPreDestory invoke");
        System.out.println("---------------destroy-----------------");
    }

    // 自定义销毁方法
    @PreDestroy
    public void springPreDestory(){
        System.out.println("LifeBean @PreDestory");
    }

    @Override
    protected void finalize() throws Throwable {
        System.out.println("------inside finalize-----");
    }


}